package com.health.controller;

import com.health.common.Result;
import com.health.entity.TRole;
import com.health.entity.pojo.vo.AdminVO;
import com.health.entity.pojo.vo.TRoleVO;
import com.health.mapper.TRoleMapper;
import com.health.service.ITRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sanchuan
 * @since 2023-04-20
 */
@Api(tags = "角色管理")
@RestController
@RequestMapping("/tRole")
public class TRoleController extends BaseController{
    @Autowired
    private ITRoleService roleService;


    @ApiOperation("获得角色列表")
    @GetMapping("/listRoles")
    public Result<TRoleVO> listRoles(){
        List<TRoleVO> roleVOList =  roleService.listRoles();
        return this.dataResult(roleVOList);
    }

    @ApiOperation("获得部门id角色列表")
    @GetMapping("/listRolesByDID/{departmentId}")
    public Result<TRoleVO> listRolesByDID(@PathVariable("departmentId") Integer departmentId){
        List<TRoleVO> roleVOList =  roleService.listRolesByDID(departmentId);
        return this.dataResult(roleVOList);
    }

    @ApiOperation("获得每个角色下的账号列表")
    @GetMapping("listAdmin/{rid}")
    public Result<AdminVO> listAdmin(@PathVariable("rid") Integer rid){
        List<AdminVO> adminVOList = roleService.listAdmin(rid);
        return this.dataResult(adminVOList);
    }

    @ApiOperation("启用/停用后台管理账号")
    @PostMapping("/updateShelves/{isShelves}/{id}")
    public Result<Boolean> updateShelves(@PathVariable("isShelves") Boolean isShelves,@PathVariable("id") Integer id){
        Boolean aBoolean = roleService.updateShelves(isShelves, id);
        return this.dataResult(aBoolean);
    }

    @ApiOperation("增加角色")
    @PostMapping("/addRole")
    public Result<Boolean> addRole(@RequestBody TRole role){
        return  this.dataResult(roleService.saveOrUpdate(role));
    }

    @ApiOperation("根据ID查找角色")
    @GetMapping("/getRoleById/{id}")
    public Result<TRoleVO> getRoleById(@PathVariable("id") Integer id){
        return  this.dataResult(roleService.getById(id));
    }

    @ApiOperation("根据ID逻辑删除角色")
    @DeleteMapping("deleteRoleById/{id}")
    public Result<Boolean> deleteRoleById(@PathVariable("id") Integer id){
        return this.dataResult(roleService.removeById(id));
    }
}
